﻿namespace Jim.K3Cloud;

public class SdkResponseStatus
{
    public int ErrorCode { get; set; }
    public bool IsSuccess { get; set; }
    public int MsgCode { get; set; }
    public List<ResponseStatusMessage> Errors { get; set; }
    public List<ResponseStatusMessage> SuccessMessages { get; set; }
    public List<ResponseStatusEntity> SuccessEntitys { get; set; }

    public override string ToString()
    {
        var sb = new StringBuilder();
        switch (this.MsgCode)
        {
            case 0:
                sb.Append("默认");
                break;
            case 1:
                sb.Append("上下文丢失");
                break;
            case 2:
                sb.Append("没有权限");
                break;
            case 3:
                sb.Append("操作标识为空");
                break;
            case 4:
                sb.Append("异常");
                break;
            case 5:
                sb.Append("单据标识为空");
                break;
            case 6:
                sb.Append("数据库操作失败");
                break;
            case 7:
                sb.Append("许可错误");
                break;
            case 8:
                sb.Append("参数错误");
                break;
            case 9:
                sb.Append("指定字段 / 值不存在");
                break;
            case 10:
                sb.Append("未找到对应数据");
                break;
            case 11:
                sb.Append("验证失败");
                break;
            case 12:
                sb.Append("不可操作");
                break;
            case 13:
                sb.Append("网控冲突");
                break;
            case 14:
                sb.Append("调用限制");
                break;
            case 15:
                sb.Append("禁止管理员登录");
                break;
        }
        if (Errors != null)
            foreach (var error in Errors)
            {
                sb.Append($":第{error.DIndex + 1}行[{error.FieldName}]:{error.Message}");
            }
        if (SuccessMessages != null)
            foreach (var success in SuccessMessages)
            {
                sb.Append($":第{success.DIndex + 1}行[{success.FieldName}]:{success.Message}");
            }
        return sb.ToString();
    }
}

public class ResponseStatusMessage
{
    public string FieldName { get; set; }
    public string Message { get; set; }
    public long DIndex { get; set; }
}

public class ResponseStatusEntity
{
    public long Id { get; set; }
    public string Number { get; set; }
    public long DIndex { get; set; }
}



public class K3CloudActionError
{
    public string ErrorTitle { get; set; }
    public string ErrorInfo { get; set; }
}